
    //遍历分类中的所有链接，点到谁谁的背景颜色变化
var parts = document.getElementsByClassName("parts")[0]
var lis = document.getElementsByClassName("lis");
//分类
(function (){
    var differparts = document.getElementsByClassName('differ-parts')[0]
    let classContainer=document.querySelector('.classContainer')
    let gridContainer=document.querySelectorAll('.gridContainer')
    parts.onmouseover = function() {
        classContainer.classList.remove('height')
    }
    parts.onmouseout = function() {
        classContainer.classList.add('height')
    }

    gridContainer[1].onmouseover = function() {
        classContainer.classList.remove('height')
    }
    gridContainer[1].onmouseout = function() {
        classContainer.classList.add('height')
    }
    classContainer.onmouseover = function() {
        classContainer.classList.remove('height')
    }
    classContainer.onmouseout = function() {
        classContainer.classList.add('height')
    }
})();

// for (i = 0; i < lis.length; i++) {
//     lis[i].onmouseover = function() {
//         this.style.background = "#f5f5f5";


//     }
//     lis[i].onmouseout = function() {
//         this.style.background = "none";


//     }

// }
// //搜索
// let nav=document.querySelector('.nav')
// let dimSearch=document.querySelector(".dimSearch")
// gridContainer[2].onclick=function(){
//     nav.style.backgroundColor="rgba(0,0,0,.3)"
//     for(let i=0;i<gridContainer.length;i++){
//         gridContainer[i].style.display="none"
//     }
//     dimSearch.style.display="block"
// }

// function htmlEscape(text){
//     return text.replace(/[<>"&]/g,function(match,pos,originalText){
//         switch(match){
//         case "<":return "&lt";
//         case ">":return "&gt";
//         }
//     });
// }

//收索框
(function(){
    let searhInput=document.querySelectorAll('.searhInput')
    let searchBtn=document.querySelectorAll('.searchBtn')
    for(let i=0;i<searhInput.length;i++){
        searhInput[i].onfocus=()=>{
            document.addEventListener('keydown', function(e) {
                var e = e || window.event
                if (!e.ctrlKey&&e.keyCode === 13) {
                    console.log(1);
                    window.location.href=`/picture/search?search=${searhInput[i].value}`
                }
            })
        }
        
        searchBtn[i].onclick=()=>{
            window.location.href=`/picture/search?search=${searhInput[i].value}`
        }
    }
})()

// axios.get('/pictrue/message').then(data=>{
//     console.log(data);
// })
function $(selector){
    var c=selector.substring(0,1);//获取第一个字符
    if(c=="#"){
        return document.getElementById(selector.substring(1,selector.length));//返回相应的元素
    }else if(c == '.'){
        return document.getElementsByClassName(selector.substring(1,selector.length))
    }else{
        return document.getElementsByTagName(selector);
    }
}
function tigs(i,yes){
    $('.tip')[0].style.opacity = '1'
    if(yes == true){
        $('.tip')[0].innerHTML = `<i class="iconfont icon-chenggong"></i>${i}`
    }else{
        $('.tip')[0].innerHTML = `<i class="iconfont icon-shibai"></i>${i}`
    }
    $('.tip')[0].style.top="200px"
    setTimeout(()=>{
        // $('.tip')[0].style.opacity="0"
        setTimeout(()=>{
            $('.tip')[0].style.top="-100px"
        },1000)
    },2000)
}


//分类
axios.get('/index/mainclassificationList')
.then(data=>{
    let arr = data.data.data.data
    let str = ''
    for(let i = 0;i < arr.length;i++){
        str += `
        <li class="lis">
            <a href="/picture/classfy?sonId=${arr[i].id}&fatherId=${arr[i].fatherId}">${arr[i].classfyName}</a>
        </li>
        `
    }
    document.getElementsByClassName('classIfy')[0].innerHTML = str
})
.catch(err=>{
    console.log(err)
})

let userLoginMessage=document.querySelectorAll('.userLoginMessage')[4]
// console.log(userLoginMessage);
if(userLoginMessage){
    userLoginMessage.onclick=function(){
        axios({
            url:'/login/exit',
        }).then(data=>{
            let message=data.data
            if(message="退出登录成功"){
                window.location.href='/login'
            }
        })
    }
}